#include <wait_read.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <ants.h>
	
int wait_read(int sock, int timeouts) {
	int state;
	fd_set rfdset; 
	struct timeval tv; 
	tv.tv_sec = timeouts; 
	tv.tv_usec = 0; 
	FD_ZERO(&rfdset); 
	FD_SET(sock, &rfdset); 
	state = select(sock+1, &rfdset, NULL, NULL, &tv);
	return state;
}	
	
int wait_read_all(struct mission *pms, fd_set *rfdset, int timeouts) {
	int i, n;
	int state;
	int max = 0;
	struct ants *ant;
	struct timeval tv;
	tv.tv_sec = timeouts; 
	tv.tv_usec = 0; 
	FD_ZERO(rfdset); 
	n = pms->thread;
	ant = pms->first_ant;
	for(i = 0; i < n; i++) {
		if(ant[i].flag & FINISH)
			continue;
		FD_SET(ant[i].s, rfdset);
		if(ant[i].s > max)
			max = ant[i].s;
	}
	state = select(max+1, rfdset, NULL, NULL, &tv);
	return state;
}	
